package org.limit.bookServe.utils;

import org.limit.bookServe.bean.User;

import java.util.ResourceBundle;
import java.util.Scanner;

import static org.limit.bookServe.utils.SystemConstants.BASE_FILE_NAME;

/**
 * @author  1.
 * @version 1.0
 * @description:  基础类
 * @date 2023/11/4 13:36
 */
public abstract class BaseClass {
    //当前用户
    private static final ThreadLocal<User> CURRENT_USER = new ThreadLocal<>();
    //配置文件读取器
    private static final ResourceBundle R = ResourceBundle.getBundle(BASE_FILE_NAME);
    public static final Scanner input = new Scanner(System.in);

    protected void setCurrentUser(User u) {
        //将用户信息加载到当前线程
        CURRENT_USER.set(u);
    }

    protected User getCurrentUserInfo() {
        return CURRENT_USER.get();
    }

    protected void removeCurrentUser() {
        //将用户信息在当前线程中移除
        CURRENT_USER.remove();
    }


    /*
    *  配置文件信息读取器
    * */
    public static String resourceReader(String key) {
        return R.getString(key);
    }

    /*
    *  简化sout
    * */
    public static void println(String s) {
        System.out.println(s);
    }

    //仅换行
    public static void println() {
        System.out.println();
    }

    /*
    *  简化不换行sout
    * */
    public static void print(String s) {
        System.out.print(s);
    }

//    public static void main(String[] args) {
//        System.out.println(resourceReader(USER_DATA_FILE_NAME));
//    }
}
